#include "Application.hpp"
#include "AbstractState.hpp"
//#include "StatePlaying.hpp"

namespace MA {

Application::Application(int width, int height, std::string title)
    : Window (width, height, title), m_running(true) {

//    setBGColor(0xFF, 0xFF, 0xFF, 0xFF);

//    loadResources();
}

Application::~Application() {
//    delete m_bgTexture;
//    delete m_textureO;
//    delete m_textureX;
}

/*
void Application::loadResources() {
    m_bgTexture = new MTexture(m_renderer, "../tic_tac_toe_#.png");

    m_textureO = new MTexture(m_renderer, "../tic_tac_toe_o.png");
    m_textureX = new MTexture(m_renderer, "../tic_tac_toe_x.png");
}
*/

int Application::run() {
    while (m_running) {
        update();
//        sleep(10);
    }

//    close();
    return 0;
}

void Application::update() {
    AbstractState* state = m_states.back();

    state->handleEvent();
    state->updateLogic();
    state->updateRender();
}

void Application::sleep(uint32_t ms) {
    SDL_Delay(ms);
}

void Application::setRunning(bool running) {
    m_running = running;
}

bool Application::isRunning() const {
    return m_running;
}

void Application::pushState(AbstractState* state) {
    m_states.push_back(state);
    m_states.back()->bindApp(this);
}

void Application::popState() {
    m_states.pop_back();
}

/*
void Application::updateLogic() {

}

void Application::onWindowQuit() {
    m_running = false;
}
*/

}
